<?php /* 	These code was generated using phpCIGen v 0.1.a (21/04/2009)
	#zaqi 		zaqi.smart@gmail.com,http://zenzaqi.blogspot.com, 
    #songbee	mukhlisona@gmail.com
	#CV. Trust Solution, jl. Saronojiwo 19 Surabaya, http://www.ts.co.id
	
	+ Module  		: m_setup Model
	+ Description	: For record model process back-end
	+ Filename 		: c_m_setup.php
 	+ creator 		: 
 	+ Created on 22/Jan/2012 19:08:53
	
*/
class M_m_setup extends CI_Model{
	function M_m_setup() {
		parent::__construct();
	}
	function m_setup_list($filter,$start,$end){
		$query = "SELECT m_setup.* FROM m_setup";		
		$result = $this->db->query($query);
		$nbrows = $result->num_rows();
		
		if($nbrows>0){
			foreach($result->result() as $row){
				$arr[$row->param1 . '01'] = $row->vvalue1;
				$arr[$row->param1 . '02'] = $row->vvalue2;
				$arr[$row->param1 . '11'] = $row->nvalue1;
				$arr[$row->param1 . '12'] = $row->nvalue2;
			}
			$jsonresult = json_encode($arr);
			return '({"total":"'.$nbrows.'","results":['.$jsonresult.']})';
		} else {
			return '({"total":"0", "results":""})';
		}
	}
	function m_setup_update($setup_cetakspk,$setup_ppn,$setup_kdvo,$setup_kcb5,$setup_kcb6,$setup_kcb7,$setup_procmarsitek,$setup_procmme,$setup_procmstruktur,
	$setup_ppnjabatan,$setup_kdvojabatan,$setup_kcb5jabatan,$setup_kcb6jabatan,$setup_kcb7jabatan,$setup_procmarsitekjabatan,$setup_procmmejabatan,
	$setup_procmstrukturjabatan,$setup_pasaljeniskontrak,$setup_pasaltypekonten,$setup_pasalkonten,$setup_procm,$setup_procmjabatan,$setup_pasalnilaikontrak,$setup_ambang,
	$setup_cetakspkcontenttype,$setup_cetakspknilaikontrak,$setup_cetakIPB, $setup_cetakIPBcontenttype, $setup_cetakIPBnilaikontrak
			,$setup_cetakPO, $setup_cetakPOcontenttype, $setup_cetakPOnilaikontrak){
	
	if($setup_pasaltypekonten !== "" && $setup_pasaltypekonten !== null && ( $setup_pasaltypekonten == 'Header' || $setup_pasalnilaikontrak !== "") ){
		if($setup_pasaltypekonten == "Header"){
			$data_update = array(
				"bvalue1"=>$setup_pasalkonten
			);
		}else{
			if ($setup_pasalnilaikontrak == 'Lebih Dari Ambang'){
				$data_update = array(
					"bvalue2"=>$setup_pasalkonten
				);
			}else{
				$data_update = array(
					"bvalue3"=>$setup_pasalkonten
				);
			}
		}
			
		$this->db->where("param1", $setup_pasaljeniskontrak);
		$this->db->update("m_setup", $data_update);
	}
		
		/* cetak spk */
		if($setup_cetakspkcontenttype !== "" && $setup_cetakspkcontenttype !== null && ( $setup_cetakspkcontenttype == 'Konten' || $setup_cetakspknilaikontrak !== "") ){
			if($setup_cetakspkcontenttype == "Konten"){
				$data_update = array(
					"bvalue1"=>$setup_cetakspk
				);
			}else{
				if ($setup_cetakspknilaikontrak == 'Lebih Dari Ambang'){
					$data_update = array(
						"bvalue2"=>$setup_cetakspk
					);
				}else{
					$data_update = array(
						"bvalue3"=>$setup_cetakspk
					);
				}
			}
				
			$this->db->where("param1", 'SPK');
			$this->db->update("m_setup", $data_update);
		}
		
		/* cetak IPB */
		if($setup_cetakIPBcontenttype !== "" && $setup_cetakIPBcontenttype !== null && ( $setup_cetakIPBcontenttype == 'Konten' || $setup_cetakIPBnilaikontrak !== "") ){
			if($setup_cetakIPBcontenttype == "Konten"){
				$data_update = array(
					"bvalue1"=>$setup_cetakIPB
				);
			}else{
				if ($setup_cetakIPBnilaikontrak == 'Lebih Dari Ambang'){
					$data_update = array(
						"bvalue2"=>$setup_cetakIPB
					);
				}else{
					$data_update = array(
						"bvalue3"=>$setup_cetakIPB
					);
				}
			}
				
			$this->db->where("param1", 'IPB');
			$this->db->update("m_setup", $data_update);
		}
		
			
		/* cetak PO */
		if($setup_cetakPOcontenttype !== "" && $setup_cetakPOcontenttype !== null && ( $setup_cetakPOcontenttype == 'Konten' || $setup_cetakPOnilaikontrak !== "") ){
			if($setup_cetakPOcontenttype == "Konten"){
				$data_update = array(
					"bvalue1"=>$setup_cetakPO
				);
			}else{
				if ($setup_cetakPOnilaikontrak == 'Lebih Dari Ambang'){
					$data_update = array(
						"bvalue2"=>$setup_cetakPO
					);
				}else{
					$data_update = array(
						"bvalue3"=>$setup_cetakPO
					);
				}
			}
				
			$this->db->where("param1", 'PO');
			$this->db->update("m_setup", $data_update);
		}
		
		$data = array(
			array('PPN',$setup_ppn,$setup_ppnjabatan),
			array('KDVO',$setup_kdvo,$setup_kdvojabatan),
			array('PURCM_ARSITEK',$setup_procmarsitek,$setup_procmarsitekjabatan),
			array('PURCM_ME',$setup_procmme,$setup_procmmejabatan),
			array('PURCM_STRUKTUR',$setup_procmstruktur,$setup_procmstrukturjabatan),
			array('PROCM',$setup_procm,$setup_procmjabatan),
			array('AMBANG',$setup_ambang,'')
		);
		foreach($data as $row){
			if($row[1] !== ''){
				if($row[0] == 'PPN' || $row[0] == 'AMBANG'){ 
					/* data numeric */
					$data_update = array(
						'nvalue1' => $row[1]
					);
				}else{
					$data_update = array( 
					/* data varchar */
						'vvalue1' => $row[1],
						'vvalue2' => $row[2],
					);
				}
				$this->db->where("param1", $row[0]);
				$this->db->update("m_setup", $data_update);
			}
		}
		/*$this->db->update('m_setup', $data);
		return "{success:true}"; */
	}
	function get_kontenkontrak($jenis_kontrak,$nilai_kontrak, $type_konten){
		if($type_konten != "Footer"){
			$kuery = "SELECT bvalue1 as konten";
		}else{
			if ($nilai_kontrak == "Lebih Dari Ambang"){
				$kuery = "SELECT bvalue2 as konten ";
			}else{
				$kuery = "SELECT bvalue3 as konten";
			}
		}
		$kuery .= " FROM m_setup WHERE param1 = '" . $jenis_kontrak . "'";
		$query = $this->db->query($kuery);
		if($query->num_rows() > 0){
			$row = $query->row();
			$result = $row->konten;
			return $result;
		}else{
			return "Undefined Content";
		}
	}
}
?>